<template>
  <dt-modal-edit ref='modal' title='渠道修改' :label-width='180' :width='600' @ok='onOk'
    :loading='loading'>
  </dt-modal-edit>
</template>

<script>
  import Opt from '../opt/ChannelOpt.js'
  import customerMgr from "@/biz/customer/customer.js"
  import channelMgr from '@/biz/channel/channel.js'
  export default {
    data() {
      return {
        info: {
          newChannelSourceName: '',
          channelSourceName: null,
          channelId: null,
          cooperationTypeName: '无',
          newCooperationTypeName: '无',
          address: [],
          annexLogList: []
        },
        loading: false
      }
    },
    mounted() {},
    methods: {
      channleAnnexLogList(customerId) {
        let params = {
          businessId: customerId,
          housesId: this.$dt.buildInfo().housesId,
          type: 'customer',
        }
        return channelMgr.channleAnnexLogList(params)
          .then((res) => {
            return res
          })
      },
      show(info) {
        this.info.customerName = info.customerName
        this.info.userCustomerId = info.userCustomerId
        this.info.channelSourceName = info.channelSourceName
        this.channleAnnexLogList(info.userCustomerId).then(res => {
          if (res && res.length > 0) {
            this.info.annexLogList = res
          } else {
            this.info.annexLogList = []
          }

          this.$refs.modal.show(new Opt(this.info, this))
        }).catch((err) => {
          this.$refs.modal.show(new Opt(this.info, this))
        })


      },
      hide() {
        this.$refs.modal.hide()
      },
      onOk() {
        let info = {
          channelId: this.info.channelId,
          address: (this.info.address && this.info.address[0]) ? JSON.stringify(this.info
            .address) : null,
          userCustomerId: this.info.userCustomerId,
        }
        let oldTip = this.info.channelSourceName ? `从“${this.info.channelSourceName}”` : ''
        this.$Modal.confirm({
          title: `客户渠道修改确认`,
          content: `确定将客户${this.info.customerName}的“来源渠道”${oldTip}修改为：${this.info.newChannelSourceName}？`,
          onOk: () => {
            customerMgr.updateCustomerChannel(info).then(res => {
              this.hide()
              this.$emit("change")
            })
          }
        })
      }
    }
  }
</script>

<style>
</style>